﻿Public Class FormProjet

    Private Sub ButtonAjouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAjouter.Click
        Dim oTache As New ClassTache
        oTache.Edit()
        If oTache.Titre <> "" Then
            Me.ListViewActivites.SuspendLayout()
            Dim oItem As ListViewItem = Me.ListViewActivites.Items.Add(oTache.Titre, "Activite")
            oItem.SubItems.Add(oTache.DateTerminee)
            oItem.Tag = oTache
            oItem.Checked = oTache.Terminee
            Me.ListViewActivites.ResumeLayout()
         End If
    End Sub

    Private Sub ListViewActivites_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListViewActivites.ItemCheck
        Dim oItem As ListViewItem = Me.ListViewActivites.Items(e.Index)
        Dim oTache As ClassTache = oItem.Tag
        oTache.Terminee = Not oItem.Checked 'La valeur est changée après l'événement
        oItem.SubItems(1).Text = oTache.DateTerminee
    End Sub

    Private Sub ListViewActivites_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListViewActivites.SelectedIndexChanged
        If ListViewActivites.SelectedItems.Count > 0 Then
            Me.TextBoxDetails.Text = ListViewActivites.SelectedItems(0).Tag.Description
        End If
    End Sub

    Private Sub ButtonModifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonModifier.Click
        If ListViewActivites.SelectedItems.Count > 0 Then
            Dim oItem As ListViewItem = ListViewActivites.SelectedItems(0)
            Dim oTache As ClassTache = oItem.Tag
            oTache.Edit()
            oItem.Checked = oTache.Terminee
            oItem.Text = oTache.Titre
            oItem.SubItems(1).Text = oTache.DateTerminee
            Me.TextBoxDetails.Text = oTache.Description
        End If
    End Sub

    Private Sub ButtonSupprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSupprimer.Click
        If ListViewActivites.SelectedItems.Count > 0 Then
            ListViewActivites.SelectedItems(0).Remove()
            Me.TextBoxDetails.Text = ""
        End If
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If MsgBox("Réinitialiser le projet et supprimer toutes les données à l'exception des fichiers ouverts?", MsgBoxStyle.Question Or MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
            Me.ListViewActivites.Items.Clear()
            Form1.ProjetCourant.Clear()
            Form1.ListViewMarqueurs.Items.Clear()
            Form1.ToolStripComboBoxCommand.Items.Clear()
            Form1.ToolStripComboBoxCommand.Text = ""
            Me.ListViewContenu.Items.Clear()
            Me.ListViewContenu.Groups.Clear()
            Dim oGroupContenu As ListViewGroup
            Dim oItemContenu As ListViewItem
            For Each oItem As ListViewItem In Form1.ListViewFichiers.Items
                Dim oDoc As ClassDocument = oItem.Tag
                oGroupContenu = Me.ListViewContenu.Groups.Add(oDoc.ID, oDoc.Historique.Liste.Count - 1 & " versions pour " & oDoc.Titre)
                Dim NoArchive As Integer = 0
                For Each oArchive As ClassArchive In oDoc.Historique.Liste
                    If Not oArchive Is Nothing Then
                        NoArchive += 1
                        oItemContenu = Me.ListViewContenu.Items.Add("Archive " & NoArchive & " (" & oArchive.DateFichier & ")", "Archive")
                        oItemContenu.Tag = oArchive
                        oItemContenu.Group = oGroupContenu
                    End If
                Next
            Next
        End If
    End Sub
End Class